<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Naturezas</title>
    </h:head>

    <ui:composition template="/index.xhtml">  
        <ui:define name="conteudo">  
            <f:view>
                <h:body>
                    <h:form id="formNaturezas" >

                        <p:growl autoUpdate="true" showDetail="true"/>

                        <p:panel header="Naturezas">

                            <p:dataTable id="dtNaturezas"
                                         var="item" 
                                         value="#{naturezaBean.naturezas}" 
                                         selectionMode="single" 
                                         selection="#{naturezaBean.natureza}"
                                         rowKey="#{item.id}"
                                         emptyMessage="N&atilde;o h&aacute; dados">

                                <p:column headerText="C&oacute;digo" 
                                          style="width: 50px"> 
                                    <center>
                                        <h:outputText value="#{item.codigo}" />
                                    </center>
                                </p:column> 

                                <p:column headerText="Descri&ccedil;&atilde;o" > 
                                    <h:outputText value="#{item.descricao}" />
                                </p:column>  

                            </p:dataTable>

                            <br/>

                            <!-- Botões para o CRUD -->

                            <p:commandButton value="Novo" 
                                             actionListener="#{naturezaBean.adicionarInicio}"
                                             oncomplete="dlgNatureza.show()" 
                                             update=":display"/>

                            <p:commandButton value="Editar" 
                                             actionListener="#{naturezaBean.editarInicio}"
                                             update=":display"/>

                            <p:commandButton value="Excluir"
                                             actionListener="#{naturezaBean.excluirInicio}"/>

                        </p:panel>
                    </h:form>

                    <!-- confirmDialog para confirmação de exclusão -->

                    <p:confirmDialog  message="Deseja excluir esse registro?"
                                      severity="alert"
                                      header="Exclus&atilde;o" 
                                      widgetVar="dlgExcluirNatureza" 
                                      appendToBody="true">  

                        <h:form>

                            <p:commandButton id="confirm" 
                                             value="Sim" 
                                             actionListener="#{naturezaBean.excluirFim}" 
                                             update=":formNaturezas:dtNaturezas"/>  

                            <p:commandButton id="decline"
                                             value="N&atilde;o" 
                                             onclick="dlgExcluirNatureza.hide();"
                                             actionListener="#{naturezaBean.cancelar}" 
                                             update=":formNaturezas:dtNaturezas" />   

                        </h:form>

                    </p:confirmDialog>

                    <p:dialog header="Natureza" 
                              widgetVar="dlgNatureza" 
                              appendToBody="true" 
                              showEffect="clip"
                              hideEffect="clip"
                              dynamic="true"
                              modal="true"
                              resizable="false">

                        <h:panelGrid id="display">

                            <ui:include src="Natureza.xhtml" />

                        </h:panelGrid>

                    </p:dialog>
                </h:body>
            </f:view>
        </ui:define>
    </ui:composition>

</html>

